//
//  NSString+BML_MD5.m
//  24-加密
//
//  Created by GivenBmli on 16/8/16.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "NSString+BML_MD5.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (BML_MD5)


- (NSString *)stingWith32BitMD5 {
//a
    const char *cSting = [self UTF8String];
    CC_LONG length = (CC_LONG)strlen(cSting);
    unsigned char bytes [CC_MD5_DIGEST_LENGTH];
//    2.将字符串转换 MD5
    CC_MD5(cSting, length, bytes);
//    3.将c的字符串转换成OC的字符串
    NSMutableString *finalMD5String = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH *2];
    
    for (int i = 0; i< CC_MD5_DIGEST_LENGTH; i++) {
        [finalMD5String appendFormat:@"%02x",bytes[i]];
    }

    return finalMD5String;
}
- (NSString *)stingWith32BitMD5Lower {
    return [[self stingWith32BitMD5]lowercaseString];
}
- (NSString *)stingWith32BitMD5Upper {
    return [[self stingWith32BitMD5]uppercaseString];
}

- (NSString *)stingWith16BitMD5 {
    NSString *md5Sting32Bit = [self stingWith32BitMD5];
  NSString *md5Sting16Bit = [md5Sting32Bit substringToIndex:md5Sting32Bit.length - 8];
    md5Sting16Bit = [md5Sting16Bit substringFromIndex:8];
    return md5Sting16Bit;
}
- (NSString *)stingWith16BitMD5Lower {
    return [[self stingWith16BitMD5 ]lowercaseString];
}
- (NSString *)stingWith16BitMD5Upper {
    return [[self stingWith16BitMD5]uppercaseString];
}






@end
